<template>
  <div class="page">
    <NavBar title="首页" :isBack="isBack" />
    <div class="main">
    <Banner />
      <ul class="nav">
        <li @click="goList(item.name)" v-for="(item,index) in nav" :key="index">
          <img :src="item.imgUrl" alt="" />
          <div>{{item.name}}</div>
        </li>
      </ul>
      <div>
      <Title :title="title" />
          <List :list='list' />
      </div>
    </div>
    <TabBar :currentIndex="currentIndex" />
  </div>
</template>
<script setup>
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import axios from "axios";
import NavBar from "../components/NavBar.vue";
import Title from "../components/Title.vue";
import Banner from "../components/Banner.vue";
import TabBar from "../components/TabBar.vue";
import List from "../components/List.vue";
import g1 from "../assets/img/g1.png";
import g2 from "../assets/img/g2.png";
import g3 from "../assets/img/g3.png";
import g4 from "../assets/img/g4.png";
import g5 from "../assets/img/g5.png";
import g6 from "../assets/img/g6.png";


import n1 from "../assets/img/1.png";
import n2 from "../assets/img/2.png";
import n3 from "../assets/img/3.png";
import n4 from "../assets/img/4.png";
import n5 from "../assets/img/5.png";
import n6 from "../assets/img/6.png";
import n7 from "../assets/img/7.png";
import n8 from "../assets/img/8.png";
const router = useRouter();
const isBack = ref(false);
const title = ref('');
let nav =[
    {
    imgUrl:n1,
    name:'历史'
  },
    {
    imgUrl:n2,
    name:'启蒙读物'
  },
    {
    imgUrl:n3,
    name:'传统文化'
  },
    {
    imgUrl:n4,
    name:'科普百科'
  },
    {
    imgUrl:n7,
    name:'漫画绘本'
  },
    {
    imgUrl:n6,
    name:'儿童文学'
  },
    {
    imgUrl:n5,
    name:'科普百科'
  },
    {
    imgUrl:n8,
    name:'英文读物'
  },
]
let list =[
  {
    imgUrl:g1,
    name:'海底两万里'
  },
  {
    imgUrl:g2,
    name:'西南联大英文课'
  },
  {
    imgUrl:g3,
    name:'图书名称长度文学名家名著：孔乙己'
  },
  {
    imgUrl:g4,
    name:'暴风雨中的孩子'
  },
  {
    imgUrl:g5,
    name:'寻常百姓家1'
  },
  {
    imgUrl:g6,
    name:'我爱天下一切狗'
  },
]
const goList = (name) => {
  router.push("/list?name="+name);
};
const currentIndex = ref(0);
onMounted(() => {
  console.log("mounted");
  getData()
  console.log(router);
});
const getData = () => {
  axios({
    url: "https://www.fastmock.site/mock/19e0bcc189f92dbee2f430b58363a785/h5/getTitle",
    method: "post",
  }).then((res) => {
    console.log(res, "返回信息·");
    title.value = res.data.data
  });
}
</script>
<style scoped lang="less">
.page {
  width: 100%;
  min-height: 100vh;
  background: #f8f8f8;
  // background-color: rgb(250, 244, 235);
}

.nav {
  width: 92%;
  height: 166px;
  background-color: #ffffff;
  border-radius: 10px;
  margin: 0 auto 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  li{
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding:0px 10px;
    img{
      width: 40px;
      height: 40px;
    }
  }
}

</style>
